import http from "@/http";

export const userListApi = (params: IUserListParams): RES<IUserListModel> =>
  http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

// 添加用户列表请求
export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

// 获取指定用户的信息
export const getUserById = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

// 修改指定用户信息
export const updateUser = (params: IUserModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

// 获取全部角色
export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

// 获取指定用户的角色
export const getRoleByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

// 给用户分配角色
export const updateUserRoleApi = (id: number, ids: number[]): RES<number> =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);

// 获取角色列表
export const getRolePageAPI = (params: IUserListParams): RES<ITableResult<IRoleList>> =>
  http.get("/role/list", { params });

// 修改角色状态
export const updateRoleStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

// 添加角色
export const cerateRoleAPI = (params: IRoleList): RES<IRoleList> =>
  http.post("/role/create", params);

// 修改角色
export const editRolesAPI = (id: number, params: IRoleList): RES<number> =>
  http.post(`/role/update/${id}`, params);

// 获取对应角色的相关资源
export const getRourceListByRoleIdApi = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);

// 获取后台全部资源
export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");

// 获取全部后台资源分类
export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");

  // 给角色分配资源
export const allocResourceApi = (paramas: allocResourcePramas) =>
  http.post(
    `/role/allocResource?roleId=${
      paramas.roleId
    }&resourceIds=${paramas.resourceIds.join(",")}`
  );

  // 返回菜单列表
export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");
